// https://blog.csdn.net/weixin_43972437/article/details/106125594
const { Controller } = require("egg");
class BaseController extends Controller {
  get user() {
    return this.ctx.session.user;
  }

  success(data) {
    this.ctx.body = {
      success: true,
      data
    };
  }

  notFound(msg) {
    msg = msg || "not found";
    this.ctx.throw(404, msg);
  }

  getNoNullObj(obj) {
    for (let key in obj) {
      if (obj[key] === "" || obj[key] === null || obj[key] === undefined) {
        delete obj[key];
      }
    }
    return obj
  }
  getWhere(obj) { 
    for (let key in obj) {
      if (obj[key] === "" || obj[key] === null || obj[key] === undefined) {
        delete obj[key];
      }
    }
    var where =' where 1=1 '
    if(Object.keys(obj)){
      for (let key in obj) {
        where += ` and ${key} like '%${obj[key]}%' `
      } 
    } 
    return where
  }
}
module.exports = BaseController;
